package com.sch.hospital.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;
import com.sch.hospital.domain.Result;
import com.sch.hospital.domain.Hospital;
import com.sch.hospital.service.IHospitalService;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 医院信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@Tag(name = "医院相关接口")
@RestController
@RequestMapping("/system/hospital")
@CrossOrigin
public class HospitalController
{
    @Autowired
    private IHospitalService hospitalService;

    /**
     * 查询医院信息列表
     */
    @GetMapping("/list")
    public Result list(Hospital hospital)
    {
        List<Hospital> list = hospitalService.selectHospitalList(hospital);
        return Result.success(list);
    }

    /**
     * 获取医院信息详细信息
     */
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(hospitalService.selectHospitalById(id));
    }

    /**
     * 新增医院信息
     */
    @PostMapping
    public Result add(@RequestBody Hospital hospital)
    {
        int rows = hospitalService.insertHospital(hospital);
        return rows > 0 ? Result.success() : Result.error("新增医院信息失败");
    }

    /**
     * 修改医院信息
     */
    @PutMapping
    public Result edit(@RequestBody Hospital hospital)
    {
        int rows = hospitalService.updateHospital(hospital);
        return rows > 0 ? Result.success() : Result.error("修改医院信息失败");
    }

    /**
     * 删除医院信息
     */
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        int rows = hospitalService.deleteHospitalByIds(ids);
        return rows > 0 ? Result.success() : Result.error("删除医院信息失败");
    }
}
